package cn.wolfcode.trip.admin.web.controller;

import cn.wolfcode.trip.base.query.BuyQueryObject;
import cn.wolfcode.trip.base.service.IBuyService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/buy")
public class BuyController {
    @Autowired
    private IBuyService buyService;
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo")BuyQueryObject qo, Model model){
        model.addAttribute("result", buyService.query(qo));
        return "buy/list";
    }

    @RequestMapping("/status")
    @ResponseBody
    public Object setStatus(Long id){
        JSONResult result = new JSONResult();
        try {
            boolean b = buyService.setStatus(id);
            result.setSuccess(b);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
}
